<?php
$myDir = dirname(__FILE__) . "/";
require_once($myDir."../autoload.php");
if ( $argc == 1 || $argv[1] == "--help" ) {
  die( "\n\tUsage: php ".$argv[0]." [CONTROLLER_NAME] [ACTION_NAME] [FULL_PATH_TO_PROJECT]\n\n");  
}

$contrName = $argv[1];
$actionName= $argv[2];
$path      = $argv[3];

require_once($path . "user_autoload.php");
$newContrConf=WebUtils::removeActionFromConfig($contrName, $actionName);
file_put_contents(Conf::get('MY_HOME'). "config/web/controllers_config.php", $newContrConf);


try {
  $reflMethod = new ReflectionMethod($contrName, $actionName);
}
 catch(ReflectionException $re) {
   die("Action ". $actionName . " isn't defined for controller ". $contrName . "\n");  
 }

$fp = fopen($path."controllers/".$contrName.".php", "r");
 
$startLine = $reflMethod->getStartLine();
$endLine   = $reflMethod->getEndLine(); 
$linesCount = 0;
$newContr = "";
while( $line = fgets($fp) ) {
  $linesCount++;
  if ( ($linesCount >= $startLine && $linesCount <= $endLine) == false ) {
    $newContr .= $line;
  }
}
fclose($fp);
file_put_contents($path."controllers/".$contrName.".php", $newContr);

 